home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / gfx / board / rtgmasdriv.lha / driver / example2.s < prev    next >
Text File  |  1997-03-28  |  9KB  |  274 lines

  1. ***************************************************
  2. * The ASM Version of the Example of the Generic   *
  3. * rtgmaster game videodriver. The Generic         *
  4. * rtgmaster videodriver is a linkable object file *
  5. * that works together with any C or ASM code and  *
  6. * should work okay as video driver for most       *
  7. * games. It already opens all needed libraries    *
  8. * and all that stuff. It is coded in C, but       *
  9. * internally calls a lot of ASM functions. It is  *
  10. * in fact used by some of the games mentioned     *
  11. * in the rtgmaster docs. This example is a simple *
  12. * example about how to use this driver.           *
  13. * The driver does not give you all features of    *
  14. * rtgmaster, but it is more easy to use for       *
  15. * people who never used libraries before.         *
  16. * You have to install the rtgmaster includes      *
  17. * to use it.                                      *
  18. ***************************************************
  19.  
  20.  Include "vid_rtgm.i"
  21.  XDEF _StartIt
  22.  
  23. _StartIt
  24.  
  25. ***************************************************
  26. * We want to copy a 320x200 rectangle, later.     *
  27. ***************************************************
  28.  
  29.     lea myrect,a0
  30.     move.l #64,vr_x(a0)
  31.     move.l #64,vr_y(a0)
  32.     move.l #128,vr_width(a0)
  33.     move.l #100,vr_height(a0)
  34.  
  35. ***************************************************
  36. * Init the modes. We want only LUT8 modes (8 Bit  *
  37. * modes. If we would like for example LUT8 or     *
  38. * RGB16 or RGB15 modes, we would provide          *
  39. * LUT8+RGB16+RGB15 as parameter. Look at          *
  40. * vid_rtgm.i for the possible constants. These    *
  41. * constants show you all colortypes available     *
  42. * on Amiga GFX Boards. Only 8 Bit is the same     *
  43. * on all boards. We want to use an invisible      *
  44. * pointer. We don't want to use an extra vram     *
  45. * buffer to be allocated (if we would want that,  *
  46. * the extra buffer would be available with the    *
  47. * variable extravram.                             *
  48. **************************************************/
  49.  
  50. ***************************************************
  51. * types :                                         *
  52. * MOVE16 = use Move16 for 8 Bit, rtgmaster        *
  53. * CopyRtgPixelArray for 15/16/24 Bit.             *
  54. * RTGMASTER = use rtgmaster CopyRtgPixelArray for *
  55. * all depths. (Move16 does not run on all hard-   *
  56. * ware, so be sure to allow this option. rtgmaster*
  57. * function is not much slower than the other      *
  58. * possible functions.                             *
  59. * BLITTER = Use the GFX Board Blitter to fake     *
  60. * Doublebuffering. This is quite slow.            *
  61. * DOUBLEBUFFER = Use Doublebuffering. This does   *
  62. * flicker on some machines.                       *
  63. ***************************************************
  64.  
  65. ***************************************************
  66. * Speed :                                         *
  67. * RTGMASTER = 1.0 (higher value = faster)         *
  68. * COPY_MOVE_MOVE without Src/Destination Offset   *
  69. * = 1.002                                         *
  70. * COPY_MOVEM_MOVEM = 1.215                        *
  71. * FCOPY = 1.227                                   *
  72. * Source of this driver is provided, so if you    *
  73. * want to change the copy function to be used,    *
  74. * simply modify the vid_rtgm.c and fcopy.s        *
  75. * files.                                          *
  76. ***************************************************
  77.  
  78. ***************************************************
  79. * 0 is no extra vram buffer, 1 is use extra vram  *
  80. * buffer. This buffer is free to do everything    *
  81. * with it you want to do with it.                 *
  82. ***************************************************
  83.  
  84. ***************************************************
  85. * Move16 and Rtgmaster use a Fastcopy Buffer for  *
  86. * buffer, the other two methods use a slower      *
  87. * Videoram Buffer.                                *
  88. ***************************************************
  89.  
  90.     move.l #LUT8,d0
  91.     move.l #MOVEM,d1
  92.     move.l #NOPOINTER,d2
  93.     move.l #0,d3
  94.  
  95. ***************************************************
  96. * This example does not use the Screenmode-       *
  97. * Requester. If you want an example using the     *
  98. * Screenmode-Requester, have a look at the C      *
  99. * example (you have to provide a MyMode structure *
  100. * in a0 then).                                    *
  101. ***************************************************
  102.  
  103.     move.l #0,a0
  104.     jsr _RTGM_Init
  105.  
  106. ***************************************************
  107. * Init the example Palette.                       *
  108. ***************************************************
  109.  
  110.     lea palette,a0
  111.     move.l #768,d1
  112. palloop:
  113.     move.b #0,(a0)+
  114.     dbra d1,palloop
  115.     lea palette,a0
  116.     move.b #255,3(a0)
  117.  
  118.     cmp.l #0,d0
  119.     beq Quit
  120.  
  121. ***************************************************
  122. * In this example we simply use the first         *
  123. * available screenmode :)                         *
  124. * An actual game should better use a Screenmode   *
  125. * of a certain size, for example 320x200.         *
  126. ***************************************************
  127.  
  128.     move.l d0,a0
  129.     move.l a0,modes
  130.     lea lvid,a1
  131.     move.l vm_width(a0),d0
  132.     move.l d0,vd_width(a1)
  133.     move.l vm_height(a0),d0
  134.     move.l d0,vd_height(a1)
  135.     move.l vm_rowbytes(a0),d0
  136.     move.l d0,vd_rowbytes(a1)
  137.  
  138. ***************************************************
  139. * Set the Mode, open the Screen, set the Palette. *
  140. ***************************************************
  141.  
  142.     move.l a1,a0
  143.     move.l modes,a1
  144.     move.l vm_setmode(a1),a2
  145.     jsr (a2)
  146.     lea lvid,a0
  147.     move.l modes,a1
  148.     lea palette,a2
  149.     move.l vm_setpalette(a1),a3
  150.     jsr (a3)
  151.     jsr _RTGM_SetPalette
  152.  
  153. ***************************************************
  154. * The Mainloop of this example consists of a      *
  155. * Buffer-Swapping (MOVE16 and RTGMASTER use       *
  156. * CPU-Copy, BLITTER uses Blitter-Copy,            *
  157. * DOUBLEBUFFER uses Doublebuffering (which does   *
  158. * not run flickerfree on some GFX Boards, support *
  159. * at least RTGMASTER !!!) To render the offscreen *
  160. * Buffer, render to lvid.buffer !!!               *
  161. * If you provide the parameter VID_WAIT_NONE, no  *
  162. * synching will be done. Synching is only needed  *
  163. * for DOUBLEBUFFERING, MOVE16, RTGMASTER and      *
  164. * BLITTER do not need it.                         *
  165. * For trying the thing out, i am initializing the *
  166. * backbuffer to some values.                      *
  167. ***************************************************
  168.  
  169.     move.l #16000,d0
  170.     sub.l #1,d0
  171.     lea lvid,a0
  172.     move.l vd_buffer(a0),a0
  173. theloop:
  174.     move.l #$01010101,(a0)+
  175.     dbra d0,theloop
  176.  
  177. ***************************************************
  178. * For "Loading..." symbols and something like that*
  179. * this driver has the calls begindirectrect and   *
  180. * enddirectrect. They store the Background.       *
  181. * They use simple longwordcopy, so they are not   *
  182. * fast. They can't handle anything bigger than    *
  183. * 24x24. They work in 8/15/16/24 Bit.             *
  184. ***************************************************
  185.  
  186.     lea lvid,a0
  187.     move.l modes,a1
  188.     move.l #160,d0
  189.     move.l #100,d1
  190.     lea symbol,a2
  191.     move.l #3,d2
  192.     move.l #3,d3
  193.     move.l vm_begindirectrect(a1),a3
  194.     jsr (a3)
  195.  
  196. ***************************************************
  197. * Wait for the user to press the left mousebutton *
  198. * to remove the thing again.                      *
  199. ***************************************************
  200.  
  201. waitloop:
  202.     btst #6,$bfe001
  203.     bne waitloop
  204.  
  205.     lea lvid,a0
  206.     move.l modes,a1
  207.     move.l #160,d0
  208.     move.l #100,d1
  209.     move.l #3,d2
  210.     move.l #3,d3
  211.     move.l vm_enddirectrect(a1),a2
  212.     jsr (a2)
  213.  
  214. mainloop:
  215.  
  216.     lea lvid,a0
  217.     move.l modes,a1
  218.     lea myrect,a2
  219.     move.l #VID_WAIT_VSYNC,d0
  220.     move.l vm_swapbuffers(a1),a3
  221.     jsr (a3)
  222.  
  223. ***************************************************
  224. * Sys_SendKeyEvent only reacts on Keypresses. If  *
  225. * you also want Mouseevents, you have to modify   *
  226. * the vid_rtgm.c or use rtgmaster functions to do *
  227. * so. Sys_SendKeyEvent returns RawKey codes or 0. *
  228. * It includes the KeyUp/KeyDown information.      *
  229. ***************************************************
  230.  
  231.     move.l modes,a1
  232.     move.l vm_sendkeyevents(a1),a2
  233.     jsr (a2)
  234.  
  235. ***************************************************
  236. * This function returns keypress information in   *
  237. * me_rawkey, qualifiers (like Shift) in           *
  238. * me_qualifier, mouse info (like MENUUP) in       *
  239. * me_mouse, and it ALWAYS returns the current     *
  240. * mouseposition in me_x and me_y.                 *
  241. * We quit on CTRL q in this example.              *
  242. ***************************************************
  243.  
  244.     move.l d0,a0
  245.     move.w me_rawkey(a0),d0
  246.     move.w me_qualifier(a0),d1
  247.     cmp.w #16,d0
  248.     bne .nope
  249.     and.w #CONTROL,d1
  250.     cmp.w #0,d1
  251.     beq .nope
  252.     bra .pressed
  253. .nope:
  254.     bra mainloop
  255.  
  256. ***************************************************
  257. * Before quitting, free all allocated resources.  *
  258. ***************************************************
  259.  
  260. .pressed:
  261.     lea lvid,a0
  262.     move.l modes,a1
  263.     move.l vm_closemode(a1),a2
  264.     jsr (a2)
  265. Quit:
  266.     rts
  267.  
  268. modes: dc.l 0
  269. lvid: dc.l 0,0,0,0,0,0,0
  270. myrect: dc.l 0,0,0,0,0
  271. palette: ds.b 769,0
  272. symbol: dc.b 1,1,1,1,1,1,1,1,1
  273.     END
  274.